#ifndef __CORE_COMMON_SERVICE_H_INCLUDE__
#define __CORE_COMMON_SERVICE_H_INCLUDE__

#include <core/common/platform.h>
#include <core/common/string.h>
#include <core/common/singleton.h>

namespace core{ namespace common
{
	class Arguments
	{
	public:
		bool   helpMode_;
		time_t lifeTime_;
		bool   resumeMode_;
		std::string configFile_;
		std::string notifierName_;

		Arguments();
		Arguments( int argc, char *argv[] );
		virtual ~Arguments();

		virtual bool parse( int argc, char *argv[] );
	};

	class Service : public core::common::Singleton<core::common::Service>
	{
		friend class core::common::Singleton<core::common::Service>;

	protected:
		bool   enabled_;
		time_t startTime_;
		time_t stopTime_;
		size_t mainThreadId_;

		core::common::Event      notifier_;
		core::common::Arguments args_;

		Service( const core::common::Arguments &args, bool installSignal );
		virtual ~Service();

		virtual void onStop(){ enabled_ = false; }
		virtual void onReload(){}

	public:
		static void signalProc( int code );
		static const char *getSignalName( int code );

		inline bool   isResumeMode() const{ return args_.resumeMode_; }
		inline time_t getLifeTime() const{ return args_.lifeTime_; }
		inline size_t getMainThreadId() const{ return mainThreadId_; }

		virtual int runLoop(){ return 0; }
		
		bool setNotifierName( const std::string &notifierName );
	};
}}

#endif //__CORE_COMMON_SERVICE_H_INCLUDE__
